--例3：使用游标实现加薪操作
--创建游标
declare cur_id cursor scroll for select PeopleId from People
--打开游标
open cur_id
--提取数据
declare @id int, @money money = 1000
fetch first from cur_id into @id
while (@@fetch_status = 0)
	begin
		update People set PeopleSalary += @money where PeopleId = @id
		fetch next from cur_id into @id
	end
--关闭游标
close cur_id
select * from People
go

--例4:使用游标删除不达标员工
select * from People
--创建
declare cur_id cursor scroll for select PeopleId,PeopleSalary from People
--打开
open cur_id
--提取
declare @id int, @money money
fetch first from cur_id into @id,@money
while(@@FETCH_STATUS = 0)
	begin
		if(@money < 10000)
		begin
			delete People where PeopleId = @id
			fetch next from cur_id into @id,@money
		end
		else
			fetch next from cur_id into @id,@money
	end
close cur_id
select * from People
go
--使用游标 实现:如果A表与B表中ID字段值相同，那么将B表中的省份，城市 修改成与A表中的城市一致（连表）

declare cur_id cursor scroll for select A.* from A inner join B on A.id = B.id
deallocate cur_id
open cur_id
declare @id int , @id1 int,@Province varchar(10),@City varchar(10)
fetch first from cur_id into @id,@Province,@City
while(@@FETCH_STATUS = 0)
	begin
			update B set B.Province = @Province , B.City = @City where B.id = @id
			fetch next from cur_id into @id,@Province,@City
	end
		
close cur_id
select * from A
select * from B